package com.service.permisson;


import com.bpms.common.CommonUtil;
import com.bpms.common.JdbcWorker;
import com.bpms.common.VO;
import com.bpms.common.VOList;
import com.bpms.esb.IService;
import com.zk.atm.utils.ConstantsAtmp;
/** 
 * ATMP 登录
 * @author menlin
 *
 */
public class Atmplogin extends com.bpms.eai.PackTool implements IService {
	
	private JdbcWorker jw = null;
	
	private VO result = new VO();
	private String ret = "1";
	private String message = "";
	private VOList voList = new VOList();
	@SuppressWarnings("unchecked")
	@Override
	public VO exec(VO arg0) {
		String userid = arg0.getAttr("userid");
		String passwd = arg0.getAttr("passwd");
		if (userid == null || passwd == null) {
			ret = "1";
			message = "用户名密码不能为空";
		} else {
			VO vo = this.login(userid, passwd);
			if (vo != null) {
				ret = "0";
				message = "登陆成功";
				voList.listData.add(vo);
			} else {
				ret = "1";
				message = "登录名或密码输入错误";
			}
		}
		result.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_MESSAGE, message);
		result.setAttr(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_RET, ret);
		result.setObj(ConstantsAtmp.ATMP_GATEWAYSERVLET_CONVERT_BPMVO_TO_JSON_VOLIST, voList);
		
		return result;
	}
	/**
	 * 登录验证
	 * @param userid
	 * @param passwd
	 * @return
	 */
	private VO login(String userid, String passwd) {
		try {
			jw = new JdbcWorker();
			VO vo = new VO();
			vo.setAttr("userid", userid);
			vo.setAttr("passwd", passwd);
			return jw.getTableVO("bpm_user", vo);
		} catch (Exception e) {
			CommonUtil.debug("", e);
		}
		return null;
	}

}
